﻿using STHPMS1.Common.C_Entity;
using STHPMS1.Common.C_Entity.Stmpms1;
using STHPMS1.ICore;
using STHPMS1.ICore.I_Core;
using STHPMS1.ICore.I_UI;
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace STHPMS1.Web.W_Controller
{
    [RoutePrefix("api/evalu")]
    public class E_EvaluController : STHPMS1.Web.W_Core.MyController
    {
        [Route("")]
        [Route("page/{page?}", Name = "GetEvaluByPage")]
        [Route("rows/{rows?}")]
        [Route("page/{page?}/rows/{rows?}")]
        public IHttpActionResult Get(string road = null, int page = 1, int rows = 10)
        {
            int p = page;
            int s = rows;

            PagingInfo info = new PagingInfo();
            info.PageIndex = p > 0 ? p - 1 : 0;
            info.PageSize = s;
            info.TotalRecords = 0;

            Expression<Func<E_Evalu, bool>> exp = null;
            if (road != null && road.ToString().Length > 0)
                exp = pre => pre.Rdwayid == road.ToString();

            var data = this.Scene.Bll.E_Evalu.Get<E_Evalu>(exp, info).ToArray();
            if (data == null) return NotFound();

            var result = new { rows = data, total = info.TotalRecords };

            return Ok(result);
        }


       


        //[Route("roadnetname")]
        //public dynamic GetRoadnetName()
        //{
        //    var innerJoinQuery =
        //       from road in this.Scene.Bll.B_Roadnet.Get<B_Roadnet>(null,null)
        //       select new { id = road.Roadnet_Id, text = road.Roadnet_Name };
        //    return innerJoinQuery;
        //}

        //[Route("netevalusave")]
        //public void GetNetevaluSave(string roadnetname, string year)
        //{
        //    this.Scene.Bll.E_Netevalu.Insert(roadnetname, year);
        //}

        [Route("GetSaveEvalu")]
        public void GetSaveEvalu(string inspecid,string rdwayid)
        {
            this.Scene.Bll.E_Evalu.Save(inspecid, rdwayid, "");
        }
    }
}